﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ImageBrowser
{
    public partial class Form1 : Form
    {
        //保存文件名全路径
        private List<string>list = new List<string>();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string[] files = Directory.GetFiles(@"d:\bbb", "*.*");
            for(var i =0;i<files.Length;i++)
            {
                string fileName = Path.GetFileName(files[i]);
                //文件名加入到listBox
                listBox1.Items.Add(fileName);
                //全路径名存入list
                list.Add(files[i]);
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            pictureBox1.Image = Image.FromFile(list[listBox1.SelectedIndex]);
        }
    }
}
